/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//function initilization()
//{


var course_id, group_id, time_id, teacher_id, room_id;
var db = openDatabase('Guiding App DB', '1.0', 'database web sql', 20 * 1024 * 1024);



db.transaction(function(query) {
  //create table (Group)
  query.executeSql('CREATE TABLE IF NOT EXISTS Grouping(Group_num INTEGER , Group_name  VARCHAR(20),Plan_id INTEGER ,FOREIGN KEY (Plan_id) REFERENCES Plan(Plan_id),  PRIMARY KEY(Group_num))');
  //query.executeSql( 'INSERT INTO Grouping VALUES (1 ,"University Mandatory",)');
  //query.executeSql( 'INSERT INTO Grouping VALUES (2 ,"University Optional")');
  query.executeSql('INSERT INTO Grouping VALUES (3 ,"Faculty Mandatory",1)');
  query.executeSql('INSERT INTO Grouping VALUES (8 ,"Faculty Mandatory",2)');
  query.executeSql('INSERT INTO Grouping VALUES (4 ,"Mandatory",1)');
  query.executeSql('INSERT INTO Grouping VALUES (5,"Mandatory",2)');
  query.executeSql('INSERT INTO Grouping VALUES (6 ,"Optional",1)');
  query.executeSql('INSERT INTO Grouping VALUES (7 ,"Optional",2)');

});
db.transaction(function(query) {
  // create table ( Course)
  query.executeSql('CREATE TABLE IF NOT EXISTS Course(Course_num VARCHAR(8), Course_name VARCHAR(40) ,Prev_course VARCHAR(8),course_level INTEGER ,PRIMARY KEY(Course_num) )');
  //CIS courses (university_mandatory)
  //query.executeSql( 'INSERT INTO Course  VALUES ("5152100","Ø§Ù„ØªØ±Ø¨ÙŠØ© Ø§Ù„ÙˆØ·Ù†ÙŠØ©" ,"" ,1,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5151100","Ø§Ù„Ø¹Ù„ÙˆÙ… Ø§Ù„Ø¹Ø³ÙƒØ±ÙŠØ©" ,"" ,1,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5112100","Ù…Ù‡Ø§Ø±Ø§Øª Ø§Ù„Ø§ØªØµØ§Ù„ Ø¨Ø§Ù„Ù„ØºØ© Ø§Ù„Ø¹Ø±Ø¨ÙŠØ©" ,"" ,1,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5101100","Ù…Ù‡Ø§Ø±Ø§Øª Ø§Ù„Ø§ØªØµØ§Ù„ Ø¨Ø§Ù„Ù„ØºØ© Ø§Ù„Ø§Ù†Ø¬Ù„ÙŠØ²ÙŠØ©" ,"" ,1,0)');
  //unvirsity_optional
  //query.executeSql( 'INSERT INTO Course  VALUES ("5102100","Ø­Ø¶Ø§Ø±Ø§Øª Ø£Ù†Ø³Ø§Ù†ÙŠØ© " ,"",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5111100","Ø§Ù„Ø«Ù‚Ø§ÙØ© Ø§Ù„Ø£Ø³Ù„Ø§Ù…ÙŠØ©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5121100","Ù†Ø¸Ø§Ù… Ø§Ù„Ø£Ø³Ù„Ø§Ù…","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5132100","Ø§Ù„ÙƒØªØ§Ø¨Ø© Ø§Ù„Ø£Ø¨Ø¯Ø§Ø¹ÙŠØ© ","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5141100","Ø§Ù„Ø«Ù‚Ø§ÙØ© Ø§Ù„Ù‚Ø§Ù†ÙˆÙ†ÙŠØ©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5142100","Ø§Ù„ØªØ°ÙˆÙ‚ Ø§Ù„ÙÙ†ÙŠ","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5161100","Ù„ØºØ© Ø£Ø¬Ù†Ø¨ÙŠØ©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5162100","Ø­Ù‚ÙˆÙ‚ Ø§Ù„Ø£Ù†Ø³Ø§Ù†","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5203100","Ù…Ù‡Ø§Ø±Ø§Øª Ø£Ø¯Ø§Ø±ÙŠØ©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5313100","Ø§Ù„Ø±ÙŠØ§Ø¶Ø© Ùˆ Ø§Ù„ØµØ­Ø©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5402100","Ù…Ø¯Ø®Ù„ Ø§Ù„Ù‰ Ø¹Ù„Ù… Ø§Ù„Ù…ÙƒØªØ¨Ø§Øª Ùˆ Ø§Ù„Ù…Ø¹Ù„ÙˆÙ…Ø§Øª","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5111104","ØªØ§Ø±ÙŠØ® Ø§Ù„Ø£Ø±Ø¯Ù† ÙˆÙÙ„Ø³Ø·ÙŠÙ†","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5201100","Ø§Ù„Ø£Ù‚ØªØµØ§Ø¯ Ø§Ù„Ø³ÙŠØ§Ø³ÙŠ Ø§Ù„Ø¹Ø§Ù„Ù…ÙŠ ","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5171100","Ù…Ø¨Ø§Ø¯Ø¦ Ø¹Ù„Ù… Ø§Ù„Ø³ÙŠØ§Ø³Ø©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5131100","Ø§Ù„Ù…Ù†Ø·Ù‚ Ùˆ Ø§Ù„ØªÙÙƒÙŠØ± Ø§Ù„Ù†Ø§Ù‚Ø¯","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5172100","Ù…Ø¯Ø®Ù„ Ø§Ù„Ù‰ Ø¹Ù„Ù… Ø§Ù„Ø£Ø¬ØªÙ…Ø§Ø¹","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5122100","Ù…Ø¨Ø§Ø¯Ø¦ Ø¹Ù„Ù… Ù†ÙØ³","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5311100","Ø¬ØºØ±Ø§ÙÙŠØ© Ø§Ù„Ø£Ø±Ø¯Ù†","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5321100","Ø£Ø«Ø§Ø± Ø§Ù„Ø£Ø±Ø¯Ù†",",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5181100","Ù…Ø¨Ø§Ø¯Ø¦ Ø¹Ù„Ù… Ø§Ù„Ø§Ø¬ØªÙ…Ø§Ø¹ÙŠ","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5182100","Ù…Ø¨Ø§Ø¯Ø¦ ÙÙŠ Ø§Ù„ØµØ­Ø© Ø§Ù„Ø¹Ø§Ù…Ø©","" ,0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5191100","Ù…Ù†Ø§Ù‡Ø¬ Ø§Ù„Ø¨Ø­Ø« Ø§Ù„Ø¹Ù„Ù…ÙŠ","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("550110","Ø§Ù„Ø¹Ù„Ù… ÙˆØ§Ù„Ù…Ø¬ØªÙ…Ø¹","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5512100","Ø§Ù„Ø²Ø±Ø§Ø¹Ø© Ø§Ù„Ù…Ù†Ø²Ù„ÙŠØ©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5522100","Ù…Ø¨Ø§Ø¯Ø¦ Ø§Ù„Ø³Ù„Ø§Ù…Ø© ÙÙŠ Ø§Ù„Ø¹Ø§Ù…Ø©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5213100","Ù…Ø¨Ø§Ø¯Ø¦ Ø§Ù„Ø·Ø§Ù‚Ø© ÙˆØ§Ù‚ØªØµØ§Ø¯Ù‡Ø§","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5312101","ØµÙ†Ø§Ø¹Ø§Øª Ø£Ø±Ø¯Ù†ÙŠØ©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5303100","Ù…Ø¨Ø§Ø¯Ø¦ ØªØºØ¯ÙŠØ© Ø§Ù„Ø§Ù†Ø³Ø§Ù†","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5502100","Ø¹Ù„Ù… Ø§Ù„Ø¨ÙŠØ¦Ø©","",0,0)');
  //query.executeSql( 'INSERT INTO Course  VALUES ("5301100","Ø§Ù„Ø£Ø³Ø¹Ø§Ù Ø§Ù„Ø£ÙˆÙ„ÙŠ","",0,0)');

//faculty mandatory
  query.executeSql('INSERT INTO Course  VALUES ("5401101","Calculus 1" ,"",1)');
  query.executeSql('INSERT INTO Course  VALUES ("5401131","Statistics" ,"",1)');
  query.executeSql('INSERT INTO Course  VALUES ("5401201","C++" ,"",2)');//1or 2
  query.executeSql('INSERT INTO Course  VALUES ("5401204","Digital Logic" ,"",2)');//1 or 2
  query.executeSql('INSERT INTO Course  VALUES ("5401231","Data Structures" ,"5402211" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5402101","Fundemental information technology" ,"" ,1)');
  query.executeSql('INSERT INTO Course  VALUES ("5402121","Web 1" ,"5402101" ,1)');
  query.executeSql('INSERT INTO Course  VALUES ("5402232","Management Information System" ,"5402101" ,2)');
});
db.transaction(function(query) {
  // speacialty mandatory 
  query.executeSql('INSERT INTO Course  VALUES ("5401102","Calculus2" ,"5401101" ,1)');// 1 or 2
  query.executeSql('INSERT INTO Course  VALUES ("5401105","Discrete" ,"" ,2)');// Ø±ÙŠØ§Ø¶ÙŠØ§Øª Ù…Ù†ÙØµÙ„Ø©
  query.executeSql('INSERT INTO Course  VALUES ("5402201","Interpersonal Communication" ,"5402101" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5401341","Algorithms" ,"5401231" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5401359","Computer Graphics" ,"5401231" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5401361","Network 1" ,"5401231" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5401473","Operating Systems " ,"5401231" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402211","Java 1" ,"5401201" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5402321","Database" ,"5401231" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5401342","Artificial Intelligence" ,"5401231" ,3)');
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO Course  VALUES ("5402351","Multimedia" ,"5402211" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5401353","Human Computer Interaction" ,"5401359" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5402353","Web 2" ,"5402121" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5402451","Geographical Information system" ,"5401359" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402471","Software Engineering" ,"5402321" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402453","Information systems applications" ,"5402321" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5401215","Advanced Programming" ,"5401201" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5402322","Security" ,"5401231" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5402475","System analysis" ,"5402321" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402352","Web Publishing" ,"5402121" ,3)');
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO Course  VALUES ("5402498","Trainning" ,"" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402495","Graduation Project" ,"" ,4)');


  // optional
  query.executeSql('INSERT INTO Course  VALUES ("5401241","Computation theory","5401105" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5402212","Java 2","5402211" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5401356","Pattern recognition","5401231" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5401203","Visual programming","5401201" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5401355","Computer-aided learning ","5402212" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5401425","Distributed Database","5402321" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5401442","Machine Learning","5401342" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5401445","Natural Language Processing ","5401342" ,4)');
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO Course  VALUES ("5402354","E_Business ","5402352" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5402252","Electronic Systems Applications ","5402232" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5401455","Image processing ","5401359" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402415","Oracle","5402321" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402345","Computer Ethics ","5402101" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5402481","Quality Management","5401131" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5401456","Expert systems and neural networks ","5401342" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402332","Decision support systems ","5402321" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5402458","Software certified","" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5401477","Design-oriented objects","5402471" ,4)');//5401471
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO Course  VALUES ("5402494","Special Topics ","" ,4)');

  // BIT 
  // speacilaty mandtory 
  query.executeSql('INSERT INTO Course  VALUES ("5202101","Accounting Principles 1 ","" ,1)');
  query.executeSql('INSERT INTO Course  VALUES ("5202211","Accounting management" ,"5202101" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5203211","Principles of Financial Management","5202101" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5201101","Principles of Business Administration","" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5402234","Operational Research" ,"5401201" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5402357","E-government" ,"5402232" ,3)');

});
db.transaction(function(query) {


// optional 
  query.executeSql('INSERT INTO Course  VALUES ("5201408"," LeaderShip in business" ,"5402232" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5202333","Accounting Information Systems" ,"5202101" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5203311","Financial Analysis" ,"5203211" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5203444","Risk Management" ,"5203211" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402235","Management Of Information Source" ,"5402101" ,2)');
  query.executeSql('INSERT INTO Course  VALUES ("5402356","Stastistcal Packages" ,"5401131" ,3)');
  query.executeSql('INSERT INTO Course  VALUES ("5402483","Business Requiermants Analysis","5402475" ,4)');
  query.executeSql('INSERT INTO Course  VALUES ("5402472","Business Intellegence Systems ","5402232" ,4)');
});
db.transaction(function(query) {

  // create Group_Course table 

  query.executeSql('CREATE TABLE IF NOT EXISTS Group_Course (Group_num INTEGER, Course_num VARCHAR(8) ,FOREIGN KEY (Group_num) REFERENCES Grouping(Group_num),FOREIGN KEY (Course_num) REFERENCES Course(Course_num) ,PRIMARY KEY (Group_num , Course_num) )');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (1,"5112100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (1,"5101100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (1,"5152100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (1,"5151100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5141100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5111100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5121100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5102100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5203100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5132100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5402100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5313100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5142100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5161100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5162100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5101104")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5201100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5171100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5131100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5172100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5122100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5311100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5321100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5181100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5182100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5191100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5501100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5512100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5522100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5213100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5312101")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5303100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5502100")');
  //query.executeSql( 'INSERT INTO  Group_Course VALUES (2,"5301100")');
  query.executeSql('INSERT INTO  Group_Course VALUES (3,"5401101")');//CAL
  query.executeSql('INSERT INTO  Group_Course VALUES (3,"5401131")');//Ø§Ø­ØµØ§Ø¡
  query.executeSql('INSERT INTO  Group_Course VALUES (3,"5401204")');//logic
  query.executeSql('INSERT INTO  Group_Course VALUES (3,"5401201")');//C++
  query.executeSql('INSERT INTO  Group_Course VALUES (3,"5401231")'); //DS
  query.executeSql('INSERT INTO  Group_Course VALUES (3,"5402101")');//Ø§Ø³Ø§Ø³ÙŠØ§Øª
  query.executeSql('INSERT INTO  Group_Course VALUES (3,"5402121")');//web1
  query.executeSql('INSERT INTO  Group_Course VALUES (3,"5402232")');//MIS
  query.executeSql('INSERT INTO  Group_Course VALUES (8,"5401101")');//CAL
  query.executeSql('INSERT INTO  Group_Course VALUES (8,"5401131")');//Ø§Ø­ØµØ§Ø¡
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (8,"5401204")');//logic
  query.executeSql('INSERT INTO  Group_Course VALUES (8,"5401201")');//C++
  query.executeSql('INSERT INTO  Group_Course VALUES (8,"5401231")'); //DS
  query.executeSql('INSERT INTO  Group_Course VALUES (8,"5402101")');//Ø§Ø³Ø§Ø³ÙŠØ§Øª
  query.executeSql('INSERT INTO  Group_Course VALUES (8,"5402121")');//web1
  query.executeSql('INSERT INTO  Group_Course VALUES (8,"5402232")');//MIS
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401102")');//cal2
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401105")');//desk
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402201")');//docum
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401341")');//algo
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401359")');//CG
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401361")');//network1
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401473")');//OS
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402211")');//java1
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402321")');//DB 
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401342")');//AI
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402351")');//Multimedia
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401353")');//HCI
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402353")');//web2
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402451")');//GIS
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402471")');//SE
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402453")');//ØªØ·ÙŠØ¨Ù‚Ø§Øª
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5401215")');//c-advance
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402322")');//securiy
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402475")');//sys analysis
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402498")');//training
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402352")');//web pup
  query.executeSql('INSERT INTO  Group_Course VALUES (4,"5402495")');//project
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401241")');//computation
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402212")');//java2
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401241")');//computation
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5403156")');// ØªÙ…ÙŠÙŠØ² Ø§Ù†Ù…Ø§Ø·
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401203")');// Ø¨Ø±Ù…Ø¬Ø© Ù…Ø±Ø¦ÙŠØ©
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401355")');// Ø§Ù„ØªØ¹Ù„Ù… Ø¨Ù…Ø³Ø§Ø¹Ø¯Ø© Ø§Ù„Ø­Ø§Ø³ÙˆØ¨
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401425")');// Ù‚ÙˆØ§Ø¹Ø¯ Ø§Ù„Ø¨ÙŠØ§Ù†Ø§Øª Ø§Ù„Ù…ÙˆØ²Ø¹Ø©
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401442")');// Ø§Ù„ØªØ¹Ù„Ù… Ø§Ù„Ø§Ù„ÙŠ
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401445")');// Ù…Ø¹Ø§Ù„Ø¬Ø© Ø§Ù„Ù„ØºØ§Øª Ø§Ù„Ø·Ø¨ÙŠØ¹ÙŠØ©
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402354")');// E-B
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402252")');// ØªØ·Ø¨ÙŠÙ‚Ø§Øª Ø§Ù„ÙƒØªØ±ÙˆÙ†ÙŠØ©
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401455")');// Ù…Ø¹Ø§Ù„Ø¬Ø© ØµÙˆØ±
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402415")');// oracle
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402345")');// ethics
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402481")');// QM
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401456")');// Ù†Ø¸Ù… Ø®Ø¨ÙŠØ±Ø©
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402332")');// DSS
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402458")');// Ø¨Ø±Ù…Ø¬ÙŠØ§Øª Ù…Ø¹ØªÙ…Ø¯Ø©
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5401477")');// ØªØµÙ…ÙŠÙ… ÙƒØ§Ø¦Ù†Ø§Øª Ù…ÙˆØ¬Ù‡Ø©
  query.executeSql('INSERT INTO  Group_Course VALUES (6,"5402494")');// STopics
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5202101")');// Ù…Ø­Ø§Ø³Ø¨Ø©1
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5202211")');// Ù…Ø­Ø§Ø³Ø¨Ø© Ø§Ø¯Ø§Ø±ÙŠØ©
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5203211")');// Ù…Ø§Ù„ÙŠØ©
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5201101")');//Ø§Ø¹Ù…Ø§Ù„
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5401341")');//algo
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5401361")');//network1
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5401473")');//OS
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402211")');//java1
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402321")');//DB 
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402471")');//SE
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402475")');//sys analysis
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402252")');// ØªØ·Ø¨ÙŠÙ‚Ø§Øª Ø§Ù„ÙƒØªØ±ÙˆÙ†ÙŠØ©
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402234")');//Ø¨Ø­ÙˆØ«
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402352")');//web pup
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402354")');// E-B
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402481")');// QM
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402201")');//docum
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402322")');//securiy
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402357")');//E-G
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402351")');//Multimedia
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402498")');//training
  query.executeSql('INSERT INTO  Group_Course VALUES (5,"5402495")');//project
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5201408")');//Ø±ÙŠØ§Ø¯ÙŠØ©
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5202333")');//Ù†Ø¸Ù… Ù…Ø­Ø§Ø³Ø¨ÙŠØ©
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5203311")');//ØªØ­Ù„ÙŠÙ„ Ù…Ø§Ù„ÙŠ
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5203444")');//Ù…Ø®Ø§Ø·Ø±
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402235")');//Ø§Ø¯Ø§Ø±Ø© Ù…ØµØ§Ø¯Ø±
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402332")');// DSS
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402345")');// ethics
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402353")');//web2
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402356")');//Ø­Ø²Ù…
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402415")');// oracle
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402458")');// Ø¨Ø±Ù…Ø¬ÙŠØ§Øª Ù…Ø¹ØªÙ…Ø¯Ø©
});
db.transaction(function(query) {
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402483")');//ØªØ­Ù„ÙŠÙ„ Ø§Ø¹Ù…Ø§Ù„
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402472")');//Ø§Ø¹Ù…Ø§Ù„ Ø°ÙƒÙŠØ©
  query.executeSql('INSERT INTO  Group_Course VALUES (7,"5402494")');// STopics

});
db.transaction(function(query) {
  // create class table
  query.executeSql('CREATE TABLE IF NOT EXISTS Class (Class_num INTEGER , Course_num VARCHAR(8) , Section_num INTEGER , Day VARCHAR(20) , Time VARCHAR(20) , Class_room VARCHAR(20) , Teacher VARCHAR(30) , Section_status VARCHAR(8), PRIMARY KEY(Class_num),FOREIGN KEY (Course_num) REFERENCES Course(Course_num)  )');
  query.executeSql('CREATE TABLE IF NOT EXISTS Course_taken (ID INTEGER PRIMARY KEY, Course_num VARCHAR(8) , year INTEGER , semester INTEGER, FOREIGN KEY (Course_num) REFERENCES Course(Course_num) )');
  query.executeSql('CREATE TABLE IF NOT EXISTS Student(  Student_id VARCHAR(10),Student_name VARCHAR(40) ,Student_pass VARCHAR(30) , Student_Department INTEGER ,year_subscription VARCHAR(8) , PRIMARY KEY(Student_id),FOREIGN KEY (Student_Department) REFERENCES Plan(Plan_id))');
query.executeSql('CREATE TABLE IF NOT EXISTS Schedule( Class_num INTEGER PRIMARY KEY )');
});
db.transaction(function(query) {
  // create table (Plan)
  query.executeSql(' CREATE TABLE IF NOT EXISTS Plan (Plan_id INTEGER , Plan_name VARCHAR(20), Plan_abr VARCHAR(3),PRIMARY KEY(Plan_id))');
  query.executeSql('INSERT INTO Plan VALUES (1 ,"Computer Information System" , "CIS")');
  query.executeSql('INSERT INTO Plan VALUES (2 ,"Business Information Technology" , "BIT")');
});


function get_doctor_name() {
  db.transaction(function(tx) {
    tx.executeSql('SELECT Teacher FROM Class group by (Teacher) ', [], function(tx, result) {
       var doctor_name, id, option_str;
        for (var i = 0; i < result.rows.length; i++) {
      
        doctor_name = result.rows.item(i).Teacher;
        id = doctor_name.replace(/ /g, "-");
        id = id.replace(/'/g, "-");
        option_str = '<option value = "' + id + '" >' + doctor_name + '</option>';
        $("#doctor_List").append(option_str);
      }

    });
  });

}
 function get_group_name (){
     db.transaction(function(tx) {
    tx.executeSql('SELECT Group_name FROM Grouping , Student  WHERE Grouping.Plan_id = Student.Student_Department', [], function(tx, result) {
        var group_name , group_id , option_str ;
        for (var i = 0; i < result.rows.length; i++) {
            group_name = result.rows.item(i).Group_name;
            group_id = group_name.replace(/ /g, "-");
            option_str = '<option value = "' + group_id + '" >' + group_name+ '</option>' ;
             $("#group").append(option_str);
            
         }
    });
     });
}

function get_Abbreviation() {
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM Plan', [], function(tx, result) {

      for (var i = 0; i < result.rows.length; i++) {
        var value = result.rows.item(i).Plan_id;
        var name = result.rows.item(i).Plan_abr;
        var str = '<input type="radio" name="dep-choice" id="dep-choice-' + value + '" value="' + value + '" /><label for="dep-choice-' + value + '">' + name + '</label>';
        $("#radio_g").append(str);
        $("#radio_g1").append(str);

      }


    });
  });

}
function Insert_Student()
{

  db.transaction(function(tx) {
    var password = $('#T_password').val();
    var pass2 = $('#T_REPassword').val();
    var Student_name = $('#Student_Name').val();
    var student_ID = $('#Student_ID').val();
    var department = $('#radio_g :checked').val();
    var year = $('#year :selected').val();
    $("#Student_Name").parent().removeClass('errorClass');
    $("#Student_ID").parent().removeClass('errorClass');
    $("#T_password").parent().removeClass('errorClass');
    $("#T_REPassword").parent().removeClass('errorClass');
    $("#radio_g").closest('legend').removeClass('errorradio');
    //  alert(department);
    if (password !== "" && pass2 !== "" && Student_name !== "" && student_ID !== "" && department !== undefined) {
      if (password === pass2)
      {
          /**var strMD5 = $().crypt({
                method: "md5",
                source: password
            });
          *****/
        tx.executeSql('INSERT INTO Student VALUES ("' + student_ID + '","' + Student_name + '","' + password + '","' + department + '","' + year + '")');
        //alert("Your Account is created and your passward is "+password );

        $.mobile.changePage("#page3");
        load_page();
        log = true;
      }
      else
              //  alert ("Check your password");

              {
                $("#T_password").parent().addClass('errorClass');
                $("#T_REPassword").parent().addClass('errorClass');

              }
    }
    else
    {
      if (Student_name === "")
        $("#Student_Name").parent().addClass('errorClass');

      if (student_ID === "")
        $("#Student_ID").parent().addClass('errorClass');
      if (password === "")
        $("#T_password").parent().addClass('errorClass');
      if (pass2 === "")
        $("#T_REPassword").parent().addClass('errorClass');
      if (department === undefined)
        $("#radio_g legend").addClass('errorradio');
      //  alert ("there is some fields are not completed");
    }

  });

}
function get_pass()
{

  db.transaction(function(tx) {

    tx.executeSql('SELECT * FROM Student', [], function(tx, result) {
      //alert(result.rows.item(0).Student_pass);
      $("#text_password").parent().removeClass('errorClass');
      dosome(result.rows.item(0).Student_pass);
    });


  });
} // end get_pass function

function dosome(data) {
  var T_password = $('#text_password').val();
  var S_password = data;
  //alert(T_password);
  if (T_password === S_password)
  {
    //alert(T_password);
    $.mobile.changePage("#page3");
    load_page();
  }
  else
  {
    //alert("the password is wrong");

    $("#text_password").parent().addClass('errorClass');
    // $('#text_password').listview('refresh');
    //  $("#text_password").blur();
    // $('#text_password').textinput();
    //$("#text_password").trigger("change");

  }
}
function load_page()
{
  $("#Course_taken div").remove();
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM Student', [], function(tx, result) {
      var dept;
      dept = result.rows.item(0).Student_Department;
      get_group(dept);


    });
  });

}
function get_group(_dept)
{
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM Grouping WHERE Plan_id =' + _dept, [], function(tx, result) {
      var len = result.rows.length, i;
      var d_name, d_num;


      for (i = 0; i < len; i++) {

        d_name = result.rows.item(i).Group_name;
        d_num = result.rows.item(i).Group_num;

        //Group_append(d_name);
        var str_h4 = '<h4>' + d_name + '</h4>';
        var str_coll = '<div data-role="collapsible" id="' + d_name.replace(" ", "-") + '">' + str_h4 + '</div>';
        $("#Course_taken").append(str_coll);
        get_courses(d_name.replace(" ", "-"), d_num);

      }// end for loop for group
      check_courses();
    });
  });

}
/*  function get_dname (_num ,_name )
 {
 db.transaction(function (tx) {
 tx.executeSql('SELECT * FROM Grouping WHERE Group_num ='+_num+'', [], function(tx, result){
 _name = result.rows.item(0).Group_name ;
 });
 });
 
 }*/


function get_courses(_name, _num)
{
  db.transaction(function(tx) {
    tx.executeSql('select c.Course_name as Course_name , c.Course_num as Course_num from Course c join Group_Course gc on gc.Course_num = c.Course_num where gc.Group_num = ' + _num, [], function(tx, result) {
      var c_num, c_name, c_str;
      var index = 1;
      var len2 = result.rows.length, j;
      $("#" + _name).append('<fieldset data-role="controlgroup"></fieldset>');
      for (j = 0; j < len2; j++) {
        c_num = result.rows.item(j).Course_num;
        c_name = result.rows.item(j).Course_name;
        //get_course_name(c_num ,c_name);
        c_str = '<input name="courses-taken" type ="checkbox" id = "checkbox' + index + '"value ="' + c_num + '"/> <label for = "checkbox' + index + '">' + c_name + '</label>';
        $("#" + _name + " fieldset").append(c_str);
        // add class .notTaken 
        //$().addClass( "notTaken" );
        index = index + 1;


      }
      $("#" + _name).collapsible();
      $("input[type='checkbox']").checkboxradio();

      $("input[type='checkbox']").change(function() {

        $(this).addClass("change");

      });
    });
  });
}


function get_course_name(_num, _name)
{
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM Course WHERE Course_num =' + _num, [], function(tx, result) {
      _name = result.rows.item(0).Course_name;

    });
  });
}
function  insert_class(_index, _classnum, _sectionnum, _sectionday, _sectiontime, __classroom, _doctorname, _stutus)
{
  db.transaction(function(tx) {
    tx.executeSql('INSERT INTO Class VALUES ("' + _index + '","' + _classnum + '","' + _sectionnum + '","' + _sectionday + '","' + _sectiontime + '","' + __classroom + '","' + _doctorname + '","' + _stutus + '")');

  });
}
function  insert_course_taken(_ID, _val)
{
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM Course_taken WHERE Course_num =' + _val, [], function(tx, result) {
      if (result.rows.length === 0)
      {
        db.transaction(function(tx) {
          tx.executeSql('INSERT INTO Course_taken VALUES ("' + _ID + '","' + _val + '","","" )');

        });
      }
    });
  });

}
function delete_course_taken(_val)
{
  db.transaction(function(tx) {
    tx.executeSql('DELETE FROM Course_taken WHERE Course_num =' + _val);
    // alert(_val);
  });
}
function check_courses()
{
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM Course_taken', [], function(tx, result) {
      for (var i = 0; i < result.rows.length; i++) {
        var c_num = result.rows.item(i).Course_num;
        //alert(c_num);
        var _courses = $("input[type='checkbox']");
        var _course = null, val, _id;
        for (var j = 0; j < _courses.length; j++) {
          _course = _courses.get(j);
          val = $(_course).val();

          //   _id =  $(_course).id();
          if (val === c_num) {
            $(_course).attr("checked", "checked");
            $(_course).checkboxradio("refresh");
          }

        }
      }
    });
  });
}
function fill_student_info() {
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM Student', [], function(tx, result) {

      var stu_name = result.rows.item(0).Student_name;
      var stu_id = result.rows.item(0).Student_id;
      var stu_pass = result.rows.item(0).Student_pass;
      var stu_dept = result.rows.item(0).Student_department;
      var s_year = result.rows.item(0).year_subscription;
      // alert(stu_dept);
      // alert(s_year);
      $("#S_Name").val(stu_name);
      $("#S_ID").val(stu_id);
      //  $("#S_ID").val(stu_id);
      //    $('#S_Name').attr("disabled",true);
      //   $('#S_ID').attr("disabled", "disabled");

    });
  });

}
function change_info() {

  db.transaction(function(tx) {
    $("#Old_password").parent().removeClass('errorClass');
    $("#new_password").parent().removeClass('errorClass');
    $("#new_REPassword").parent().removeClass('errorClass');
    tx.executeSql('SELECT * FROM Student', [], function(tx, result) {
      var S_pass = result.rows.item(0).Student_pass;
      var S_id = result.rows.item(0).Student_id;
      var T_pass = $('#Old_password').val();
      var new_pass = $('#new_password').val();
      var new_repass = $('#new_REPassword').val();
      var _department = $('#radio_g1 :checked').val();
      var _year = $('#year1 :selected').val();
      if (S_pass === T_pass)
      {
        tx.executeSql('UPDATE Student Set Student_Department =' + _department + ' Where Student_id ="' + S_id + '"');
        tx.executeSql('UPDATE Student Set year_subscription ="' + _year + '" Where Student_id ="' + S_id + '"');
        if (new_pass === new_repass)
          tx.executeSql('UPDATE Student Set Student_pass ="' + new_pass + '" Where Student_id ="' + S_id + '"');
        else
        {
          $("#new_password").parent().addClass('errorClass');
          $("#new_REPassword").parent().addClass('errorClass');

        }

      }
      else
        $("#Old_password").parent().addClass('errorClass');

    });
  });

}
function  delete_student() {
  db.transaction(function(tx) {
    tx.executeSql('DELETE FROM Student');

  });

}
function delete_classes() {
  db.transaction(function(tx) {
    tx.executeSql('DELETE FROM Class');
  });
}
function delete_coursetaken() {
  db.transaction(function(tx) {
    tx.executeSql('DELETE FROM Course_taken');
  });
}

function  check_student()
{
  db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM Student', [], function(tx, result) {
      if (result.rows.length > 0)
        $("[type='submit']").button("disable");
      /*if ( result.rows.length === 0  ) 
       $( "[type='reset']" ).button( "disable" );*/
    });
  });
}
/*  function check_display_profile()
 {
 db.transaction(function (tx) {
 tx.executeSql('SELECT * FROM Student' , [], function(tx, result ){
 if (result.rows.length > 0)
 $( "[type='reset']" ).button( "enable" );
 });
 });
 }*/
function compare()
{
    $("#available").remove();
    $("#schedule").remove();
    $("#marker").after('<fieldset id ="available"><legend>Available Courses </legend></fieldset>');
    $("#available").after('<fieldset id="schedule" data-role="collapsible"><legend>Schedule </legend></fieldset>');
  db.transaction(function(tx) {
    tx.executeSql('SELECT Course.Course_name ,Class.Class_num ,Course.course_level, Course.Course_num ,Class.Section_num , Grouping.Group_name ,Class.Day , Class.Time , Class.Teacher , Class.Class_room, Class.Section_status From Course ,Class , Course_taken , Grouping ,Group_Course , Student WHERE Student.Student_Department = Grouping.Plan_id AND Grouping.Group_num = Group_Course.Group_num AND Course.Course_num = Group_Course.Course_num AND (Course.Prev_course = Course_taken.Course_num OR Course.Prev_course ="" ) AND Course.Course_num = Class.Course_num AND Course.Course_num NOT IN ( SELECT Course_taken.Course_num FROM Course_taken) Group by Class.Class_num ', [], function(tx, result) {
      var len = result.rows.length, i, Course_num, Course_name, course_level ,Class_num, section, group, day, time, teacher, room, status;
      var str;
      var course_id, group_id, time_id, teacher_id, room_id;
      var Course_num_text, section_text, group_text, day_text, time_text, teacher_text, room_text, status_text;
      for (i = 0; i < len; i++)
      {
          
        Class_num =  result.rows.item(i).Class_num;    
        Course_name = result.rows.item(i).Course_name;
        Course_num = result.rows.item(i).Course_num;
        course_level = result.rows.item(i).course_level;
        Course_num_text = "Course number : " + Course_num;
        section = result.rows.item(i).Section_num;
        section_text = "Section number : " + section;
        group = result.rows.item(i).Group_name;
        group_text = "Group name : " + group;
        day = result.rows.item(i).Day;
        day_text = "Day : " + day;
        time = result.rows.item(i).Time;
        time_text = "Time : " + time;
        teacher = result.rows.item(i).Teacher;
        teacher_text = "Teacher : " + teacher;
        room = result.rows.item(i).Class_room;
        room_text = "Classroom : " + room;
        status = result.rows.item(i).Section_status;
        status_text = "Section status : " + status;
        course_id = Course_name.replace(/ /g, "-");
        group_id = group.replace(/ /g, "-");
        time_id = time.replace(/:/g, "-");
        teacher_id = teacher.replace(/ /g, "-");
        teacher_id = teacher_id.replace(/'/g, "-");
        room_id = room.replace(/ /g, "-");

        str = '<div class="'  + Course_num + ' ' + day + ' ' + course_level+' '+time_id + ' ' + group_id + ' ' + teacher_id + ' course" id ="' + Course_num + '' + section + '" data-time = "'+time_id+'" data-classid ="'+ Class_num + '" data-role="collapsible"> <legend>' + Course_name + '</legend>  <ul data-role="listview"> <li>' + Course_num_text + '</li> <li>' + section_text + '</li> <li >' + group_text + '</li> <li  >' + time_text + '</li> <li >' + day_text + '</li> <li >' + teacher_text + '</li> <li>' + room_text + '</li> <li>' + status_text + '</li> </ul> </div>';

        $("#available").append(str);
        $("#schedule").append(str);
        $("#schedule .course").addClass('hidecourse');
        //$("#available").trigger("create");

        $("#available #" + Course_num + section).collapsible();
        $("#schedule #" + Course_num + section).collapsible();
        $("#available #" + Course_num + section).prepend(' <a class="add-to-schedual" data-role ="button" data-inline="true" data-mini="true"  data-icon="arrow-d" data-iconpos="notext" >Add</a>');
        $("#schedule #" + Course_num + section).prepend(' <a class="add-to-available" data-role ="button" data-inline="true" data-mini="true"  data-icon="arrow-u" data-iconpos="notext" >Delete</a>');

        //  alert ( time_id);


      }
      $("#available").collapsible();
      $("#schedule").collapsible();
      $(".add-to-schedual , .add-to-available").button();
  
      $(".add-to-schedual").click(function(event) {
        //event.preventDefault();
        
      //  var course = $(this).parents(".course").clone();
      $(this).parents(".course").addClass('hidecourse');
      var id = $(this).parents(".course").attr('id');
      $("#schedule #"+id).removeClass('hidecourse');
      var time = $(this).parents(".course").data('time');
      $("#available ."+ time +" .add-to-schedual").addClass('ui-disabled');
     
      
       
       // $("#schedule").append(course);
        
        //$(this).remove();
          
        // return  false ;
      });
  $(".add-to-available").click(function(event) {
           $(this).parents(".course").addClass('hidecourse');
            var id = $(this).parents(".course").attr('id');
            $("#available #"+id).removeClass('hidecourse');
            var time = $(this).parents(".course").data('time');
            $("#available ."+ time+" .add-to-schedual").removeClass('ui-disabled');
            
      });
      
    });
  });

}

function  insert_to_sch(){
     var courses = $("#schedule .course").not('.hidecourse');
     var course = "" ;
    // var id ;
     
       //  id = course.data('classid');
        db.transaction(function(tx) {
          tx.executeSql('delete from Schedule');
          for( var i = 0 ; i < courses.length ; i++ ){
            course = '(' + $(courses.get(i)).data('classid') + ')';
            tx.executeSql('INSERT INTO Schedule( Class_num ) VALUES ' + course );
          }
        });
}

function last_guide(){
          var  class_id , str ;
       db.transaction(function(tx) {
           tx.executeSql('SELECT Class_num FROM Schedule', [], function(tx, result) {
              
                for (var i = 0; i < result.rows.length; i++) {
                     class_id  = result.rows.item(i).Class_num ;
                     db.transaction(function(tx) {
                   tx.executeSql('SELECT Course.Course_name ,Class.Course_num ,Class.Section_num ,Class.Day,Class.Time ,Class.Teacher ,Class.Class_status  FROM Course , Class WHERE Class.Class_num =' +class_id+' AND Course.Course_num = Class.Course_num', [], function(tx, result) {
                       for (var j = 0; j < result.rows.length; j++) {
                           
                       }
                   });
                   });
                 
                     
                 }//end for loop 
           });
       });
    //  db.transaction(function(tx) {
   // tx.executeSql('SELECT Course.Course_name ,Class.Course_num ,Class.Section_num ,Class.Day,Class.Time ,Class.Teacher ,Class.Class_status FROM Course , Class WHERE Class.Class_num = ', [], function(tx, result) {
    
}